var filename = null;
var content = null;
var title = "";
//var description = "";
var destinationNodeId;
// locate file attributes
for each (field in formdata.fields)
{
  
  if (field.name == "destination")
  {
	destinationNodeId=search.findNode(field.value);
  }
  else if (field.name == "filedata" && field.isFile)
  {
    content = field.content;
  }
  else if (field.name == "filename")
  {
    filename = field.value;
  }
}

// ensure mandatory file attributes have been located
try{
	if (filename == undefined || content == undefined)
	{
	  status.code = 400;
	  status.message = "Uploaded file cannot be located in request";
	  status.redirect = true;
	}
	else
	{
	  // create document in company home for uploaded file
	  upload = destinationNodeId.createFile(filename) ;
	  upload.properties.content.write(content);
	  upload.properties.title = filename;
	  //upload.properties.description = description;
	  upload.save();
	  //upload.properties.content.guessMimetype(filename);
	  //upload.addAspect("cm:author");
	  //upload.addAspect("rn:renditioned");
	  //upload.createThumbnail("webpreview",false);

	  // setup model for response template
	  model.upload = upload;
	}
}catch(e){
		status.code = 500;
		status.message = "File upload error, check your parameters!!";
		status.redirect = true;
		model.upload = e.message;
}